<template>
    <div class="registerMail">
        <Card>
            <div class="over mb10">
                <Button type="primary" class="fr" style="margin:7.5px 20px 0;" @click="back">返回</Button>
                 <Button type="primary" class="fr" style="margin:7.5px 0 0;" @click="submit">提交</Button>
            </div>
            <div class="common_br">
                <h2 class="common_title"> <Button type="primary" class="fr" style="margin-right: 20px;" @click="edit">编辑</Button></h2>
                <!-- 邮寄信息模块 -->
                <mail-info
                :mailInfoDeatil="mailInfo"
                ></mail-info>
            </div>
            <div class="common_br">
                <h2 class="common_title" style="font-size: 16px;"> 归档信息 </h2>
                <div class="common_content">
                    <Form ref="queryForm" :model="queryForm"  :label-width="140">
                        <Row>
                            <Col span="10">
                                <FormItem label="申请编号/客户名称" prop="custom">
                                    <Input v-model="queryForm.custom"  placeholder=""  class="w200"/>
                                </FormItem>
                            </Col>
                             <Col span="10">
                                <div style="padding-left: 80px;">
                                    <Button type="primary" icon="ios-search" @click="handleSearch()">搜索</Button>
                                    &nbsp;&nbsp;&nbsp;&nbsp;
                                    <Button  icon="ios-trash-outline" @click="handleReset()">重置</Button>
                                    &nbsp;&nbsp;&nbsp;&nbsp;
                                </div>
                          </Col>
                      </Row>
                    </Form>
                    <div style="margin-top: 30px;">
                        <Table stripe :columns="customColumns" :data="customList" border>
                            <template slot-scope="{ row, index }" slot="action" v-if="row.statusFile!=3 && row.statusFile!=5">
                                <Button type="primary" size="small" style="margin-right: 5px" @click="archiveMail(row.cacontractId)">归档邮寄</Button>
                            </template>
                        </Table>
                        <br/>
                        <div class="page">
                            <Page :current="pageData.pageNumber" :transfer="true" :total="pageData.total" :page-size="pageData.pageSize" @on-change="changePage($event)"
                                    @on-page-size-change="changePageSize($event)" :page-size-opts="pageSizeOpts" size="small" show-total
                                    show-elevator show-sizer></Page>
                        </div>
                    </div>
                </div>
            </div>
            <div v-show="fileInfoList.length>0">
                <h2 class="file_title mb10" style="font-size:16px;color: #515a6e">文件信息</h2>
                <file-info
                :fileInfoList="fileInfoList"
                @turnPage="turnPage"
                @turnPageSize="turnPageSize"
                :isEdit="isEdit"
                :total="total"
                @deleteFile="deleteFile"
                @compileFile="compileFile"
                >
                </file-info>
            </div>
         </Card>
         <div v-if="isShowWayBill">
            <waybill-model
            @close-model="closeModel"
            @showRegisterMail="showRegisterMail"
            :operType="operType"
            :editId="mailInfo.id"
            :pcompanyList="pcompanyList"
            ></waybill-model>
        </div>
        <div v-if="isShowArchiveMail">
            <archvie-mail
            :cacontractId="cacontractId"
            :id="id"
            @close-archiveMail-model="closeArchiveMailModel"
            ></archvie-mail>
        </div>
    </div>
</template>
<script>
import {orderMail,postDocList} from '_p/afs-apply/assets/js/staticData.js'
import ArchvieMail from "../mail-archive/archiveMail.vue"
import waybillModel from "../waybill-model/waybillModel.vue"
import MailInfo from "../common/mail-info.vue"
import FileInfo from "../common/file-info.vue"
import {
    getmailDetail,
    getDocList,
    deletePostDocInfo,
    editPostInfo,
    getCodes,
    submitPostInfo
} from "_p/afs-apply/api/mail-manage/orderMailList.js";
export default {
    name:"",
    data(){
        return{
            postNo:"",//运单编号
            isEdit:true,
            fileInfoList:[],
            total:0,
            pageSize:10,
            pageIndex:1,
            mailInfo:{},
            operType:"",
            id:"",//邮寄单id
            isShowWayBill:false,
            isShowArchiveMail:false,
            pcompanyList:[],
            pageSizeOpts:[10,20,50,100],
            pageData:{
                pageNumber:1,
                pageSize:10,
                total:0
            },
            // 文件信息
            queryForm:{
                custom:"",

            },
            customColumns:[
                {
                    title: '申请编号',
                    key: 'camainNo'
                },
                {
                    title: '客户姓名',
                    key: 'borrowerName'
                },
                {
                    title: '归档状态',
                    key: 'statusfilename'
                },
                {
                    title:"最后邮寄期限",
                    key:"limitDate"
                },
                {
                    title: '操作',
                    slot: 'action',
                    align: 'center'
                }
            ],
            customList:[],
        }
    },
    components:{
        ArchvieMail,
        waybillModel,
        MailInfo,
        FileInfo
    },
    mounted(){
        console.log(this.afs.getPageParams(this),"this.afs.getPageParams(this)")
        if (this.afs.getPageParams(this)) {
            this.id=this.afs.getPageParams(this).id;
            console.log(this.id,"this.id")
            this.editPostMsg();
        }
        this.initData();
        this.handleSearch();
    },
    watch:{
    },
    methods:{
        initData(){
            let param={
                obj:{
                    "typeId":"",
                }
            }
            getCodes(param).then(res=>{
                if (res.code == "0000") {
                    this.pcompanyList=res.data['00001HKYK9DD40000A23'];
                }
            })
        },
        // 编辑回显运单信息
        editPostMsg(){
            let params={
                id:this.id,
            };
            editPostInfo(params).then(res=>{
                if(res.code=="0000"){
                    let obj={
                        pcompany:res.data.pCompany,
                        id:res.data.id,
                        memo:res.data.memo,
                        pDate:res.data.pDate,
                        postNo:res.data.postNo,
                        pUserId:res.data.pUserId
                    }
                   this.mailInfo=obj;
                   this.postNo=res.data.postNo;
                   this.initmailDetail();
                }
            })

        },
        changePage(number){
            this.pageData.pageNumber=number;
            this.queryDocList();
        },
        changePageSize(size){
            this.pageData.pageSize=size;
            this.queryDocList();
        },
        // 查询归档列表
        queryDocList(){
            let params={
                category:"",
                pageIndex:this.pageData.pageNumber,
                pageSize:this.pageData.pageSize,
                key:this.queryForm.custom,
                status:"",
            }
            console.log(params,"registerMail")
            getDocList(params).then(res=>{
                // 当返回成功的时候
                if(res.code=="0000"){
                    this.pageData.total=res.data.total;
                    let tempArr=[];
                    res.data.records.forEach((item,index)=>{
                        let obj={
                            cacontractId:item.cacontractId,
                            camainNo:item.camainNo,
                            borrowerName:item.borrowerName,
                            statusFile:item.statusFile,
                            statusfilename:item.refData.statusfilename,
                            limitDate:item.limitDate,
                        }
                        tempArr.push(obj);
                    })
                    this.customList=tempArr;
                }
            })
        },
        handleSearch(){
            this.queryDocList();
        },
        handleReset(){
            this.$refs['queryForm'].resetFields();
            this.queryDocList();
        },
        // 点击归档邮寄
        archiveMail(cacontractId){
            this.isShowArchiveMail=true;
            this.$emit("open-model");
            this.cacontractId=cacontractId;
        },
        // 点击邮寄信息编辑
        edit(){
            this.isShowWayBill=true;
            this.$emit("open-model")
            this.operType="edit"
        },
        // 点击叉号关闭运单弹框
        closeModel(value){
            this.isShowWayBill=value;
        },
        // 关闭归档弹框
        closeArchiveMailModel(value,type){
            this.isShowArchiveMail=value;
            // if(type=="submit"){
                this.initmailDetail();
            // }
        },
        // 查询邮包详情
        initmailDetail(){
            let params={
                 postNo:this.postNo,
                 pageSize:this.pageSize,
                 pageIndex:this.pageIndex,
            }
            getmailDetail(params).then(res=>{
                if(res.code="0000"){
                    this.total=res.data.dcPostDetail.total;
                    // 文件信息
                    let tempArr=[];
                    res.data.dcPostDetail.records.forEach(item => {
                        let obj={
                            id:item.id,
                            cacontractId:item.caContractId,
                            dcpostfileCamainNo:item.camainNo,//申请编号
                            caafterCard:item.caafterCard,//证件号码
                            caafterBorrowername:item.caafterBorrowername,//客户姓名
                            statusfilename:item.refData.statusfilename,//归档状态
                            statusName:item.refData.statusName,//案件状态中文
                            md5List:item.md5List
                        }
                        if(item.names){
                            let filetypes=item.names.split(',');
                            obj.filetypes=filetypes;
                        }
                        tempArr.push(obj);
                    });
                    this.fileInfoList=tempArr;
                }
            })
        },
        turnPageSize(pageData){
            this.pageSize=pageData.pageSize;
            this.initmailDetail()
        },
        turnPage(pageData){
            this.pageIndex=pageData.pageNumber;
            this.initmailDetail()
        },
        // 删除文件信息列表
        deleteFile(fileid){
            let params={
                    id:fileid,
            }
            deletePostDocInfo(params).then(res=>{
                if(res.code=="0000"){
                    this.$Message.success("删除归档列表成功");
                    this.initmailDetail();
                }
            })
        },
        // 文件列表下面编辑
        compileFile(cacontractId){
            this.isShowArchiveMail=true;
            this.$emit("open-model");
            this.cacontractId=cacontractId;
        },
        // 点击保存关闭运单弹框
        showRegisterMail(){
            this.isShowWayBill=false;
            this.editPostMsg();
        },
        back(){
            this.afs.closeTab(this);
        },
        // 点击提交按钮
        submit(){
            if(this.fileInfoList.length==0){
                this.$Message.success("没有邮寄的文件");
                return;
            }
            let params={
                  id:this.id
            };
            submitPostInfo(params).then(res=>{
                if(res.code=="0000"){
                    this.$Message.success("提交成功");
                    this.back();
                }
            })
        }
    }
}
</script>
<style scoped>
.page{
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.postNo>>>.ivu-form-item-content{
    font-size: 0;
}
</style>
